package com.DFB.controller;


import com.DFB.common.model.Result;
import com.DFB.pojo.Property;
import com.DFB.pojo.Specification;
import com.DFB.service.SpecificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 规格表 前端控制器
 * </p>
 *
 * @author DFB
 * @since 2023-09-11
 */
@Slf4j
@RestController
@RequestMapping("/specification")
public class SpecificationController {

    @Autowired
    SpecificationService specificationService;

    // 增
    @PostMapping("/addSpecification")
    public Result add(@RequestBody Specification specification){
        log.info("add:{}",specification);
        specificationService.save(specification);
        return Result.success();
    }

    // 查
    @GetMapping("/specificationList")
    public Result<List<Specification>> get(){
        log.info("get");
        List<Specification> list = specificationService.list();
        return Result.success(list);
    }

    @GetMapping("/specificationList/{id}")
    public Result<Specification> getbyid(@PathVariable Long id){
        log.info("getbyid:{}",id);
        Specification specification = specificationService.getById(id);
        return Result.success(specification);
    }


    // 删
    @DeleteMapping("/delSpecification/{id}")
    public Result delete(@PathVariable Long id){
        log.info("delete:{}",id);
        specificationService.removeById(id);
        return Result.success();
    }

    // 改
    @PutMapping("/updateSpecification")
    public Result update(@RequestBody Specification specification){
        log.info("update:{}",specification);
        specificationService.updateById(specification);
        return Result.success();
    }
}

